#include <iostream>
using namespace std;
#include <fstream>

int main(int argc,char*argv[])
{
    //文件打开
    ofstream out;
    out.open("data.txt");

    if(!out.is_open())
    {
        cerr<<"打开失败\n";
        return -1;
    }

    //文件IO 文本形式读写
    int x=100;
    double y = 3.14;

    out<<x<<endl;
    out<<y<<endl;

    //文件关闭
    out.close();

    //读取文件
    ifstream in;
    in.open("data.txt",fstream::in);
    if(!in.is_open())
    {
        cerr<<"打开失败\n";
        return -1;
    }

    //文件IO
    int _x;
    double _y;

    in>>_x;
    in>>_y;

    cout<<"x:"<<_x<<endl;
    cout<<"y:"<<_y<<endl;

    //文件关闭
    in.close();


    return 0;
}